//
//  PackageInfo.m
//  HWZB
//
//  Created by 许成雄 on 2017/4/26.
//  Copyright © 2017年 wonders. All rights reserved.
//

#import "PackageInfo.h"
#import "ProductInfo.h"

@implementation PackageInfo

+ (NSDictionary *)JSONKeyPathsByPropertyKey {
    return @{
             @"packageId" : @"id",
             @"commodityId" : @"productId",
             @"packageName" : @"productModelName",
             @"packageDesc" : @"productModelDisc",
             @"price" : @"price",
             @"combinePrice" : @"comboPrice",
             @"imageUrl" : @"image1",
             @"imageUrl2" : @"image2",
             @"imageUrl3" : @"image3",
             @"imageUrl4" : @"image4",
             @"imageUrl5" : @"image5",
             @"productArray" : @"subs"
             };
}

+ (NSValueTransformer *)packageIdJSONTransformer {
    return [MTLValueTransformer transformerWithBlock:^id(id value) {
        if([value isKindOfClass:[NSNumber class]]) {
            return [value stringValue];
        } else {
            return (NSString *)value;
        }
    }];
}

+ (NSValueTransformer *)commodityIdJSONTransformer {
    return [MTLValueTransformer transformerWithBlock:^id(id value) {
        if([value isKindOfClass:[NSNumber class]]) {
            return [value stringValue];
        } else {
            return (NSString *)value;
        }
    }];
}

+ (NSValueTransformer *)priceJSONTransformer {
    return [MTLValueTransformer transformerWithBlock:^id(id value) {
        if([value isKindOfClass:[NSNumber class]]) {
            return [value stringValue];
        } else {
            return (NSString *)value;
        }
    }];
}

+ (NSValueTransformer *)combinePricePriceJSONTransformer {
    return [MTLValueTransformer transformerWithBlock:^id(id value) {
        if([value isKindOfClass:[NSNumber class]]) {
            return [value stringValue];
        } else {
            return (NSString *)value;
        }
    }];
}

+ (NSValueTransformer *)productArrayJSONTransformer {
    return [MTLValueTransformer reversibleTransformerWithBlock:^id(id value) {
        NSArray *packageArray = [MTLJSONAdapter modelsOfClass:[ProductInfo class] fromJSONArray:value error:nil];
        return packageArray;
    }];
}

@end
